typeList = [{
		name: "剧集"
	},
	{
		name: "电影"
	},
	{
		name: "综艺"
	},
	{
		name: "动漫"
	},
	{
		name: "音乐"
	},
	{
		name: "教育"
	},
	{
		name: "纪实"
	},
	{
		name: "体育"
	},
	{
		name: "电影"
	},
	{
		name: "娱乐"
	},
	{
		name: "动漫"
	},
	{
		name: "音乐"
	},
	{
		name: "教育"
	},
	{
		name: "纪实"
	},
	{
		name: "体育"
	},
	{
		name: "电影"
	},
	{
		name: "娱乐"
	},
	{
		name: "动漫"
	},
	{
		name: "音乐"
	},
	{
		name: "教育"
	},
	{
		name: "纪实"
	},
	{
		name: "音乐"
	},
	{
		name: "教育"
	},
	{
		name: "纪实"
	},
	{
		name: "体育"
	},
	{
		name: "电影"
	},
	{
		name: "娱乐"
	},
	{
		name: "动漫"
	},
	{
		name: "音乐"
	},
	{
		name: "教育"
	},
	{
		name: "纪实"
	}
]
//注册首页路由组件
var home = {
	template: "#home",
	data: function() {
		return {
			isshow: false,
			tip: "更多选项",
			types: typeList,
			showList: "",
		}
	},
	beforeRouteEnter: function(to, fm, next) {
		$.post("/index", {}, function(data) {
			next(function(vm) {
				data = JSON.parse(data)
				vm.showList = data;
				waterFall(vm, ".AVli");
			})
		})
	},
	beforeRouteLeave: function(to, fm, next) {
		next();
	},
	mounted: function() {
		setInterval(function() {
			var picBox = $("#picBox");
			var li = $("#picBox li").eq(0);
			$(li).animate({ "marginLeft": "-100%" }, 1000, function() {
				picBox.append(li);
				this.style.marginLeft = "0px";
			})
		}, 5000);
	},
	methods: {
		changTip: function() {
			if(this.isshow) {
				this.isshow = false;
				this.tip = "更多选项"
			} else {
				this.isshow = true;
				this.tip = "收起选项"
			}
		}
	}
}
//注册详情页组件
var details = {
	template: "#details",
	data: function() {
		return {
			detailData: "data"
		}
	},
	beforeRouteEnter: function(to, fm, next) {
		$.post("/itemDetail", { obj: to.query.id }, function(data) {
			//修改时间格式
			data.obj.createTime = data.obj.createTime.toString();
			var _index;
			for(var i = 0; i < data.obj.createTime.length; i++) {
				if(data.obj.createTime[i] == "G") {
					_index = i
				}
			}
			var _time = '';
			for(var i = 0; i < _index; i++) {
				_time += data.obj.createTime[i]
			}
			data.obj.createTime = _time
			next(function(vm) {
				vm.detailData = data.obj
			})
		}, "json")
	}
}

//注册全局路由
var router = new VueRouter({
	routes: [{
			path: "/",
			component: home
		},
		{
			path: "/details",
			component: details
		}
	]
});

new Vue({
	el: "#app",
	router: router
})
//===============================================================
//瀑布流事件逻辑封装
function waterFall(_this, _class) {
	window.onscroll = function() {
		var AVli = $(_class);
		if(AVli.length !== 0) {
			//获取最后一个盒子距离页面顶部高度
			var _height = AVli[AVli.length - 1].offsetTop;
			//获取滚动条高度
			var scroll_height = document.body.scrollTop;
			//获取浏览器窗口高度
			var window_height = document.documentElement.clientHeight || document.body.clientHeight;
			//检测最后一个盒子是否出现在浏览器窗口
			var result = scroll_height + window_height > _height ? true : false;
			if(result) {
				_this.showList.forEach(function(item, index) {
					_this.showList.push(item)
				})
			}
		} else {
			console.log("页面跳转了")
		}

	}
}